/*
继承
https://www.bilibili.com/video/BV1gf4y1r79E/?p=19&spm_id_from=pageDriver&vd_source=8bd7b24b38e3e12c558d839b352b32f4
*/
package main

import "fmt"

type Human struct {
	name string
	sex  string
}

func (this *Human) Eat() {
	fmt.Println("Human.Eat()...")
}

func (this *Human) Walk() {
	fmt.Println("Human.Walk()...")
}

type SuperMan struct {
	Human // SuperMan类继承了Human类的方法
	level int
}

// 重定义父类的方法Eat()
func (this *SuperMan) Eat() {
	fmt.Println("SuperMan.Eat()...")
}

// 子类添加新方法
func (this *SuperMan) Fly() {
	fmt.Println("SuperMan.Fly...")
}

func main() {
	h := Human{"zhang3", "male"}
	h.Eat()
	h.Walk()

	fmt.Println("=============================")

	// 方式1
	s := SuperMan{Human{"lizi", "male"}, 2}
	s.Eat()
	s.Walk()
	s.Fly()

	fmt.Println("=============================")

	// 方式2
	var s2 SuperMan
	s2.name = "liuyang"
	s2.sex = "male"
	s2.level = 4
	s2.Eat()
	s2.Walk()
	s2.Fly()
}
